@echo off
setlocal

:: 设置版本号
set VERSION=1.0.0
set BUILD_TIME=%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%
set BUILD_TIME=%BUILD_TIME: =0%

:: 创建发布目录
if not exist release mkdir release

:: 创建临时目录
mkdir release\windows
mkdir release\linux
mkdir release\windows\config
mkdir release\linux\config

:: 复制配置文件
copy /Y config\config.json "release\windows\config\"
copy /Y config\server.json "release\windows\config\"
copy /Y config\config.json "release\linux\config\"
copy /Y config\server.json "release\linux\config\"

:: 构建 Windows 客户端
echo Building Windows client...
set GOOS=windows
set GOARCH=amd64
go build -ldflags "-X main.Version=%VERSION% -X main.BuildTime=%BUILD_TIME%" -o "release\windows\client.exe" .\cmd\client

:: 构建 Linux 客户端
echo Building Linux client...
set GOOS=linux
set GOARCH=amd64
go build -ldflags "-X main.Version=%VERSION% -X main.BuildTime=%BUILD_TIME%" -o "release\linux\client" .\cmd\client

:: 构建 Windows 服务端
echo Building Windows server...
set GOOS=windows
set GOARCH=amd64
go build -ldflags "-X main.Version=%VERSION% -X main.BuildTime=%BUILD_TIME%" -o "release\windows\server.exe" .\cmd\server

:: 构建 Linux 服务端
echo Building Linux server...
set GOOS=linux
set GOARCH=amd64
go build -ldflags "-X main.Version=%VERSION% -X main.BuildTime=%BUILD_TIME%" -o "release\linux\server" .\cmd\server

:: 打包 Windows 文件
cd release\windows
powershell Compress-Archive -Path "*" -DestinationPath "..\natproxy_windows_%VERSION%.zip" -Force
cd ..\..

:: 打包 Linux 文件
cd release\linux
powershell Compress-Archive -Path "*" -DestinationPath "..\natproxy_linux_%VERSION%.zip" -Force
cd ..\..

:: 清理临时目录
rmdir /S /Q release\windows
rmdir /S /Q release\linux

echo Build complete! 